import { Modal } from 'antd';
import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react';


interface IRef {
  edit?: () => any;
  callback?: () => any;
}




const AddModal: React.ForwardRefRenderFunction<IRef, any> = (props, ref) => {

  const [modalVisible, setModalVisible] = useState(false);
  const [btnLoading, setBtnLoading] = useState<boolean>(false);
  const [editRow, setEditRow] = useState<any>(null);


  const handleCancel = () => {
    setModalVisible(false);
  };
  // 关闭弹窗 去掉loading
  useEffect(() => {
    if (!modalVisible) setBtnLoading(false);
  }, [modalVisible]);

  useImperativeHandle(ref, () => ({
    edit: (row?: any) => {
      setEditRow(row);
      setModalVisible(true);
    }
  }));


  return (
    <>
      <Modal
        title='公告内容'
        onCancel={handleCancel}
        visible={modalVisible}
        width={640}
        maskClosable={false}
        footer={[]}
        okButtonProps={{
          loading: btnLoading
        }}
        >
        {
          editRow?.content
        }
      </Modal>
    </>
  );
};

export default forwardRef(AddModal);
